import { loadCorpus } from './lib/corpus.js'
import { createRandomPicker } from './lib/random.js'
import { generator } from './lib/generator.js'

// fs.readFile('./corpus/data.json', { encoding: 'utf-8' }, (err, data) => {
//   if (err) {
//     console.log(err)
//   }else{
//     console.log(data)
//   }
// })

// const url = import.meta.url  //获取一个文件的绝对路径  __filename
// const path = resolve(dirname(fileURLToPath(url)), 'corpus/data.json')
// console.log(path);


const corpus = loadCorpus('./corpus/data.json')

// // 同步读取
// const data = fs.readFileSync(path, { encoding: 'utf-8' })
// const corpus = JSON.parse(data)
// // console.log(corpus)

const title = createRandomPicker(corpus.title)()
// const famous = createRandomPicker(corpus.famous)()
// const bosh = createRandomPicker(corpus.bosh)()

// console.log(title);
// console.log(famous);
// console.log(bosh);


const article = generator(title, {corpus, min:2000, max:3000})
console.log(title);
console.log(article);